/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						      color_cube.h

	$Header: /resource_editor/color_cube.h $

	$NoKeywords: $

 ************************************************************************/

#ifndef COLOR_CUBE_H_INCLUDED
#define COLOR_CUBE_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <vector>
#include "color_count.h"
#include "color_sum.h"

//------------------------------------------------------------
// cube in the color volume, including actual color counts
//------------------------------------------------------------
class t_color_cube : public t_color_sum
{
public:
	t_color_cube();
	
	int    get_min_color( t_axis axis ) const;
	int    get_max_color( t_axis axis ) const;
	void   init( std::vector<t_color_count_ptr>& colors ); // initialize from color counts
	t_axis cut( t_color_cube& right_cube );  // divide into 2 smaller spaces
	void   set_indexes( t_uint16 index );
	void   verify();
protected:
	void cut( int axis, t_color_cube& right_cube, int color_value ); // divide a a specific color
	// find best place to cut volume into 2 spaces
	int  find_best_cut( int axis, t_color_sum& best_sum, __int64& best_delta ) const;

	t_color_count_list m_pixels[3];    // color counts sorted by channel
	int                m_max_color[3]; // exclusive
	int                m_min_color[3]; // inclusive
};

inline int t_color_cube::get_max_color( t_axis axis ) const
{
	return m_max_color[axis];
}

inline int t_color_cube::get_min_color( t_axis axis ) const
{
	return m_min_color[axis];
}


#endif // COLOR_CUBE_H_INCLUDED